home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / RECT.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  4KB  |  89 lines

  1. #ifndef RECTANGLE_H
  2. #define RECTANGLE_H
  3.  
  4. #include "object.h"
  5. #include "point.h"
  6.  
  7. extern const Class class_Rectangle;
  8. class OrderedCltn;  // for areasOutside method
  9.  
  10. ////////////////////////////////////////////////////////////
  11. // class Rectangle (declaration)
  12. ////////////////////////////////////////////////////////////
  13. class Rectangle: public Object {
  14.     Point tl;   // top left corner (origin)
  15.     Point br;   // bottom right corner (corner)
  16. public:
  17.                 // constructors, destructors
  18.                 Rectangle(int left=0, int top=0, int width=0, int height=0);
  19.                 Rectangle(Point, Point);
  20.  
  21.                 // operators
  22.     bool        operator==(const Rectangle&) const;
  23.     bool        operator!=(const Rectangle&) const;
  24.     Rectangle   operator&&(const Rectangle&) const;     // intersection
  25.     Rectangle   operator||(const Rectangle&) const;     // union
  26.     void        operator+=(const Point&);               // translate
  27.     void        operator-=(const Point&);
  28.  
  29.     Point   origin()            const   { return tl; }
  30.     Point   origin(const Point& p)      { return tl = p; }
  31.     Point   corner()            const   { return br; }
  32.     Point   corner(const Point& p)      { return br = p; }
  33.     Point   topLeft()           const   { return tl; }
  34.     Point   topCenter()         const   {
  35.                                           return
  36.                                           Point((br.x()-tl.x())/2,tl.y());
  37.                                         }
  38.     Point   topRight()          const   { return Point(br.x(),tl.y()); }
  39.     Point   rightCenter()       const   {
  40.                                           return
  41.                                           Point(br.x(),(br.y()-tl.y())/2);
  42.                                         }
  43.     Point   bottomRight()       const   { return br; }
  44.     Point   bottomCenter()      const   {
  45.                                           return
  46.                                           Point((br.x()-tl.x())/2,br.y());
  47.                                         }
  48.     Point   bottomLeft()        const   { return Point(tl.x(),br.y()); }
  49.     Point   leftCenter()        const   {
  50.                                           return
  51.                                           Point(tl.x(),(br.y()-tl.y())/2);
  52.                                         }
  53.     Point   center()            const   {
  54.                                           return
  55.                                           Point((br.x()-tl.x())/2,
  56.                                                 (br.y()-tl.y())/2);
  57.                                         }
  58.     int     width()             const   { return (br.x()-tl.x())+1; }
  59.     void    width(int w)                { br=Point(tl.x()+w-1, br.y()); }
  60.     int     height()            const   { return (br.y()-tl.y())+1; }
  61.     void    height(int h)               { br=Point(br.x(), (tl.y()+h-1));  }
  62.     int     left()              const   { return tl.x(); }
  63.     void    left(int x)                 { tl=Point(x, tl.y()); }
  64.     int     top()               const   { return tl.y(); }
  65.     void    top(int y)                  { tl=Point(tl.x() ,y); }
  66.     int     area()              const   { return width()*height(); }
  67.     Point   extent()            const   { return Point(width(), height()); }
  68.  
  69.     OrderedCltn&    areasOutside(const Rectangle&)      const;
  70.     bool            contains(const Point&)              const;
  71.     bool            contains(const Rectangle&)          const;
  72.     bool            intersects(const Rectangle&)        const;
  73.     void            moveTo(const Point&);
  74.     Rectangle       expandBy(int i)             
  75.                     {
  76.                         return Rectangle(tl-Point(i,i), br+Point(i,i));
  77.                     }
  78.  
  79.     virtual Object*         copy()                  const;
  80.     virtual void            deepenShallowCopy();
  81.     virtual unsigned        hash()                  const;
  82.     virtual const Class*    isA()                   const;
  83.     virtual bool            isEqual(const Object&)  const;
  84.     virtual void            printOn(ostream& strm)  const;
  85.     virtual const Class*    species()               const;
  86. };
  87.  
  88. #endif
  89.